package com.jacobson.huobi.services

import android.app.Service
import android.content.Intent
import android.os.IBinder
import com.jacobson.core.widget.logger.LoggerFactory
import com.jacobson.huobi.Constants
import com.jacobson.huobi.utils.NotificationHelper

/** 应用进入后台时候发送前台通知用于保活 */
class KeepAliveService : Service(){
    private val logger = LoggerFactory.getLogger(KeepAliveService::class.java)

    override fun onBind(intent: Intent?): IBinder? {
        return null
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        startForeground(Constants.NOTIFICATION_ID_KEEP_ALIVE, NotificationHelper.createForegroundNotification(this))
        return super.onStartCommand(intent, flags, startId)
    }

    override fun onDestroy() {
        super.onDestroy()
        stopForeground(true)
        logger.d("keepLiveService is destroy!!!")
    }
}